<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>部门管理</title>
    <link rel="shortcut icon" th:href="@{/img/favicon.ico}"/>
    <link rel="bookmark" th:href="@{/img/favicon.ico}" type="image/x-icon"/>
    <link th:href="@{/css/style.css}" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" th:src="@{/js/jquery.js}"></script>
    <script type="text/javascript">
        function tipOpen(content, num, chagestate) {
            $(".tipright p").text(content);
            $("#tip").fadeIn(200);
            $("#did").val(num);
            $("#chagestate").val(chagestate);

        }

        function tipClose() {
            $("#tip").fadeOut(200);

            var did = $("#did").val();
            var chagestate = $("#chagestate").val();
            location.href = "/erp1/sys/dept/updatestate?id=" + did + "&chagestate=" + chagestate;
        }

        function tipClose2() {
            $("#tip").fadeOut(200);
        }
    </script>
</head>

<body>
<div class="place"><span>位置：</span>
    <ul class="placeul">
        <li><a th:href="@{/sys/users/userall}">系统管理</a></li>
        <li><a th:href="@{/sys/dept/deptList}">部门管理</a></li>
    </ul>
</div>
<div class="rightinfo">
    <form th:action="@{/sys/dept/deptList}" method="post" id="deptform">
        <input type="hidden" name="pageno" value="1" id="pageno"/>
        <ul class="tools">
            <li><label>部门名称:</label>
                <input type="text" name="deptName" th:value="${dept.deptName}"/>
            </li>
            <li> 所属区域：
                <select name="pId" onchange="getCity(this.value)">
                    <option value="0">请选择省份</option>
                    <option th:each="p:${session.provinces}" th:text="${p.pName}" th:value="${p.id}"
                            th:selected="${p.id==dept.pId}"
                    ></option>
                </select>
                <select name="cId">
                    <option value="0">请选择城市</option>
                    <!--<option th:value="${dept.city.id}" th:text="${dept.city.cName}">请选择</option>-->
                </select>
            </li>


            <li class="subBut" onclick="goPage(1)"><img th:src="@{/images/t06.png}"/>查询</li>
            <li class="subBut" onclick="window.location.href='deptAdd.html'"><img th:src="@{/images/t01.png}"/>添加</li>
            <li class="subBut" onclick="reset()"><img th:src="@{/images/t03.png}"/>重置</li>
        </ul>
        <table class="tablelist">
            <thead>
            <tr>
                <th>序号</th>
                <th>部门编号</th>
                <th>部门名称</th>
                <th>所属地区</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <tr th:each="d,var : ${dpInfo.list}">
                <td th:text="${(dpInfo.pageNum-1)*dpInfo.pageSize+var.count}"></td>
                <td th:text="${d.deptId}">003</td>
                <td th:text="${d.deptName}">财务部</td>
                <td th:text="${d.province.pName}">深圳</td>
                <td th:text="${d.deptState=='1'?'正常':'注销'}"></td>
                <td>
                    <a th:href="@{'/sys/dept/goUpdate/'+${d.deptId}}" class="tablelink">修改</a>
                    <input type="hidden" id="chagestate"/>
                    <input type="hidden" id="did"/>
                    <a href="javascript:void(0)" th:if="${d.deptState.equals('1')}" class="tablelink"
                       th:onclick="@{'tipOpen(\'是否确认禁用此条信息？\','+${d.deptId}+',2)'}">禁用</a>
                    <a href="javascript:void(0)" th:if="${d.deptState.equals('2')}" class="tablelink"
                       th:onclick="@{'tipOpen(\'是否确认启用此条信息？\','+${d.deptId}+',1)'}">启用</a>

                </td>
            </tr>
            </tbody>
        </table>
        <div class="pagin">
            <div class="message">共<i class="blue" th:text="${dpInfo.total}"></i>条记录，当前显示第&nbsp;<i class="blue"
                                                                                                  th:text="${dpInfo.pageNum}">2&nbsp;</i>页
            </div>
            <ul class="paginList">
                <li class="paginItem">
                    <a href="javascript:void(0);" th:onclick="goPage([[${dpInfo.isFirstPage?1:dpInfo.pageNum-1}]])">
                        <span th:class="${dpInfo.isFirstPage?'pagepre':'pagenxt roate'}"></span>
                    </a>
                </li>
                <li th:class="${page==dpInfo.pageNum?'paginItem current':'paginItem'}"
                    th:each="page : ${dpInfo.navigatepageNums}">
                    <a href="javascript:;" th:text="${page}" th:onclick="goPage([[${page}]])">1</a>
                </li>
                <li class="paginItem">
                    <a href="javascript:void(0);"
                       th:onclick="goPage([[${dpInfo.isLastPage?dpInfo.pages:dpInfo.pageNum+1}]])">
                        <span th:class="${dpInfo.isLastPage?'pagepre roate':'pagenxt'}"></span>
                    </a>
                </li>
            </ul>
        </div>
    </form>
    <!-- 提示框 -->
    <div id="tip" class="tip">
        <div class="tiptop"><span>提示信息</span><a onclick="tipClose()"></a></div>
        <div class="tipinfo"><span><img src="../../images/ticon.png"/></span>
            <div class="tipright">
                <p></p>
                <cite>如果是请点击确定按钮 ，否则请点取消。</cite></div>
        </div>
        <div class="tipbtn">
            <input name="" type="button" class="sure" value="确定" onclick="tipClose()"/>
            &nbsp;
            <input name="" type="button" class="cancel" value="取消" onclick="tipClose2()"/>
        </div>
    </div>
</div>
<script th:inline="javascript">
    $('.tablelist tbody tr:odd').addClass('odd');
    //域内容发生变化的事件

    //submit提交
    function goPage(num) {
        // alert(num);
        $("#pageno").val(num);
        $("#deptform").submit();
    }

    //重置
    function reset() {
        $("input[name=deptName]").val("");
        $("select[name=pId]>option:eq(0)").attr("selected", "true");
    }

    function getCity(num) {
        // alert(num);

        var cid = [[${dept.cId}]];
        //异步请求
        $.get("/erp1/ajaxCity", {"pid": num}, function (data) {
            // JSON.parse(data);  data--->object
            //清空内容
            // console.log(data);
            $("select[name=cId]").html("");
            var options = "<option value=''>请选择城市</option>";
            $.each(data, function (i, e) {
                if (cid = e.id) {
                    options += "<option value='" + e.id + "' selected>" + e.cname + "</option>";
                } else {
                    options += "<option value='" + e.id + "'>" + e.cname + "</option>";
                }
            });
            $("select[name=cId]").append(options);
        }, "json");
    }
</script>
</body>
</html>
